import Base from './Base'
import {USER_TYPE, IDENTITY_CARD_TYPE} from '@/lib/const'
// import Department from './Department'

class User extends Base {
  constructor ({
    id = '',
    account = '',
    address = '',
    province = '',
    city = '',
    county = '',
    name = '',
    mobile = '',
    email = '',
    roles = [],
    identityType = IDENTITY_CARD_TYPE[0].key,
    identityCard = '',
    userType = USER_TYPE[0].key,
    organizationName = '',
    organizationCode = '',
    investmentStyle = '',
    isHoldings = false,
    integral = '0',
    integralRule = ''
  }) {
    super({id})

    this.account = account
    this.address = address
    this.province = province
    this.city = city
    this.county = county
    this.name = name
    this.mobile = mobile
    this.email = email
    this.roles = roles
    this.identityType = identityType
    this.identityCard = identityCard
    this.userType = userType
    this.organizationName = organizationName
    this.organizationCode = organizationCode
    this.investmentStyle = investmentStyle
    this.isHoldings = isHoldings
    this.integral = integral
    this.integralRule = integralRule
  }

  static async login (params) {
    let res = await User.$http.get('/login', {params})
    return res
  }

  static async logout () {
    let res = await User.$http.get('/logout')
    return res
  }
  // 获取当前用户信息
  static async getCurrent () {
    let res = await User.$http.get(`${User.$name}/current`)
    return res
  }
  // 证件是否存在
  async checkIdCard () {
    let {identityCard} = this
    let params = {identityCard}
    let res = await User.$http.get(`${User.$name}/identity_card/exist`, {params})
    return res
  }
  // 机构是否存在
  async checkOrg () {
    let {organizationName, organizationCode} = this
    let params = {organizationName, organizationCode}
    let res = await User.$http.get(`${User.$name}/organization/exist`, {params})
    return res
  }
  // 保存密码
  async updatePassword ({id = this.id, oldPassword, newPassword}) {
    let res = await User.$http.post(`${User.$name}/update/password`, {id, oldPassword, newPassword})
    return res
  }
}
// 静态属性
User.$name = '/user'
export default User
